﻿using CloudDcPc.Entity;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc.FuckDlg
{
    /// <summary>
    /// UserAddDlg.xaml 的交互逻辑
    /// </summary>
    public partial class UserAddDlg : Window
    {
        ObservableCollection<User> all_User = null;
        public UserAddDlg(ObservableCollection<User> all_User)
        {
            this.all_User = all_User;

            InitializeComponent();
            if (App.user.Type != 4)   //不是总经理
            {
                tb_zjl.Visibility = Visibility.Collapsed;
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string user_num = txt_user_num.Text;
            string uname = txt_uname.Text;
            string dep = txt_dep.Text;
            if (user_num == "" || uname == "")
            {
                MessageBox.Show("用户编号或名字不能为空！");
                return;
            }
            int type = Int32.Parse(((TextBlock)cb_type.SelectedItem).Tag.ToString());
            if(App.UserBean.GetUserByField("user_num",user_num)!=null){
                MessageBox.Show("当前员工号已经存在！");
                return;
            }
            User user = new User(0, user_num, uname, "", dep, type);
            if (App.UserBean.AddUser(user))
            {
                MessageBox.Show("添加成功！");
                all_User.Add(user);
                this.Close();
            }else{
                MessageBox.Show("添加失败！");
            }
        }
        /// <summary>
        /// 关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
